<div class="formContainer" >
	<?php $this->displayFormErrors();	?>
	<form  method="post" action="<?php echo $this->url(array('ctrl' => 'tests', 'act' => 'add'))?>" >
		<fieldset class="ui-widget ui-widget-content ui-corner-all">
			<legend class="ui-widget ui-widget-header ui-corner-all"><?php echo $this->escape($this->title);?></legend>
			<p>
				<label for="testId">Test</label>
				<select id="testId" name="testId" class="text ui-widget-content ui-corner-all" >
					<option value="-1" >--------------------------------</option>
					<?php
						if($this->tests):
							foreach ($this->tests as $test):
								?><option value="<?php echo $test->id;?>" ><?php echo $this->escape($test->name. ' -- '.$test->subject);?></option><?php
							endforeach;
						endif; 
					?>
				</select>
			</p>
			<p>
				<label for="questionId">Question</label>
				<select id="questionId" name="questionId" class="text ui-widget-content ui-corner-all" >
					<option value="-1" >--------------------------------</option>
				</select>
			</p>
			<p>
				<label for="_desc">Answer</label>
				<textarea id="_desc" name="_desc"   class="text ui-widget-content ui-corner-all" ></textarea>
			</p>
			<p>
				<input class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="submit" value="Add Answer" />
			</p>
		</fieldset>
	</form>
</div>
<script type="text/javascript">
	$(function(){
		var $tests = $('#testId'),
			$questions = $('#questionId');
		$tests.change(function(){
			if(this.value == -1){
				return;
			}
			$.ajax({
				url: '<?php echo $this->url(array('ctrl' => 'questions', 'act' => 'testQuestions'));?>',
				type: 'get',
				data: 'testId='+this.value,
				dataType: 'json',
				success: function(fromServer){
					if(!fromServer){
						return;
					}
						
					var len = 	fromServer.length,
						 i = 0;
					for(; i < len; i++){
						$questions.append('<option value="'+fromServer[i].id+'">'+fromServer[i]._desc+'</option>');
					}
				}
			});
		});
	});
</script>